package suanfa;

import java.util.HashSet;
import java.util.Set;

public class test4 {
    public int lengthOfLongestSubstring(String s) {
        int Maxlength = 0;
        for (int i = 0; i < s.length(); i++) {
            int length = 0;
            Set<Character> set = new HashSet<Character>() {
            };

            set.add(s.charAt(i));
            length++;
            for (int j = i + 1; j < s.length(); j++) {
                if (!set.contains(s.charAt(j))) {
                    set.add(s.charAt(j));
                    length++;
                } else {
                    break;
                }
            }
            if (length > Maxlength) {
                Maxlength = length;
            }
        }
        return Maxlength;
    }
}
